package com.outsider.tool.rsa;
/**
 * 快速幂工具类
 * 求解a^b mod m
 * O(log b)
 * @author outsider
 *
 */
public class FastPower {
   public static Long getResult(int a,int b,int m){
	   return power(a,b,m);
   }
   private static Long power(int a,int b,int m){
	   if (b==1) return (long) a;
	   if (b==0) return (long) 1;
	   if (b%2==1) return (a* (power(a,(b/2),m) % m) * (power(a,(b/2),m) % m));
	   else return ((power(a,(b/2),m) % m) * (power(a,(b/2),m) % m));
   }
}
